package com.haofengsoft.scce.adapter.information;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.haofengsoft.scce.R;
import com.haofengsoft.scce.common.config.ConstantConfig;
import com.haofengsoft.scce.ui.consultation.ConsultationDetailActivity;

import java.util.List;

/**
 * Created by admin on 2015/7/26.
 */
public class StampCommentAdapter extends BaseAdapter {

    private Context context;
    private List<StampCommentModel> commentModelList;
    private LayoutInflater inflater = null;

    public StampCommentAdapter(Context context, List<StampCommentModel> commentModelList) {
        this.context = context;
        this.commentModelList = commentModelList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return this.commentModelList.size();
    }

    @Override
    public Object getItem(int position) {
        return this.commentModelList.get(position);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = inflater.inflate(R.layout.consultation_stamp_comment_item, null);
        TextView titleTv = (TextView) view.findViewById(R.id.stamp_comment_item_title_tv);
        TextView detailTv = (TextView) view.findViewById(R.id.stamp_comment_item_detail_tv);
        TextView timeTv = (TextView) view.findViewById(R.id.stamp_comment_item_time_tv);
        RelativeLayout itemRl = (RelativeLayout) view.findViewById(R.id.info_stamp_comment_item_rl);
        StampCommentModel tipModel = commentModelList.get(position);
        titleTv.setText(tipModel.getTitle());
        detailTv.setText(tipModel.getContent());
        timeTv.setText(tipModel.getDateTime());
//        itemRl.setOnClickListener(new ItemClickListener(zhongNanModel));
        return view;
    }

    class ItemClickListener implements View.OnClickListener {

        ZhongNanModel zhongNanModel;

        public ItemClickListener(ZhongNanModel zhongNanModel) {
            this.zhongNanModel = zhongNanModel;
        }

        @Override
        public void onClick(View view) {
            Intent consultationDetailIntent = new Intent(context, ConsultationDetailActivity.class);
            String sourceUrl = ConstantConfig.API_URL + ConstantConfig.INFO_CONNECT_WEB_URL + zhongNanModel.getId();
            consultationDetailIntent.putExtra("sourceUrl", sourceUrl);
            consultationDetailIntent.putExtra("title", zhongNanModel.getTitle());
            consultationDetailIntent.putExtra("time", zhongNanModel.getTime());
            consultationDetailIntent.putExtra("source", zhongNanModel.getSoure());
            consultationDetailIntent.putExtra("newsId", zhongNanModel.getId());
            consultationDetailIntent.putExtra("general", zhongNanModel.getDetail());
            context.startActivity(consultationDetailIntent);
        }

    }

    static class ViewHolder {
        TextView titleTv;
        TextView detailTv;
        TextView timeTv;
    }
}
